<?php
class FunctionComponent {

	/*
	 Ham  dung de cat lay ra n ky tu tu 1 doan van ban
	 */
	function CutText($text, $n) {
		// String is shorter than n, return as is
		if (strlen($text) <= $n) {
			return $text;}
			 
			$text= substr($text, 0, $n);
			if ($text[$n-1] == ' ') {
				return trim($text)."...";
			}
			 
			$x  = explode(" ", $text);
			$sz = sizeof($x);
			if ($sz <= 1)   {
				return $text."...";}
				 
				$x[$sz-1] = '';
				 
				return trim(implode(" ", $x))."...";
	}
}
?>